import Vue from 'vue'
import Vuex from 'vuex'
import tasklist from './modules/TaskList'
import createPersistedState from "vuex-persistedstate";
Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    tasklist
  },
  getters: {
    taskList: (state) => state.tasklist.taskList,
    stateList: (state) => {
      if (state.tasklist.state === '-1') {
        return state.tasklist.taskList.filter(item=> !item.state)
      }
      if (state.tasklist.state === '1') {
        return state.tasklist.taskList.filter(item=> item.state)
      }
      return state.tasklist.taskList
    },
    state: (state) => state.tasklist.state,
    taskNumber: (state) => state.tasklist.taskList.length,
    isShow: (state) => {
      const show = state.tasklist.taskList.every(item => item.state)
      if ( show ) {
        return true
      } else {
        return state.tasklist.isShow
      }
    },
  },
  plugins: [createPersistedState({
    key: "TODOLIST",
    paths: ['tasklist']
  })]
})